package net.liteheaven.xblib.common.convert;

public class StringUtil {
	
	/**
	 * 
	 * 获取包含子串的数目 
	 * @throw 
	 * @return int
	 */
	public static int getSubStringCount(String src, String sub){
		int start = 0;
		int count = 0;
		while(true){
			int pos = src.indexOf(sub, start);
			if (pos == -1){
				break;
			}
			count++;
			start = pos+1;
		}
		return count;
	}
	
	/**
	 * 
	 * 在首部移除一行 
	 * @throw 
	 * @return void
	 */
	public static void removeLineAtFirst(StringBuffer sb){
		int pos = sb.indexOf("\n");
		if(pos == -1){
			return;
		}
		sb.delete(0, pos+1);
	}

    /**
     * 分割字符串，获取最后一段
     * @param src
     * @param separator
     * @return
     */
    public static String getLastPart(String src, String separator){
        String ret = "";
        if (!src.isEmpty()){
            int lastSepPos = src.lastIndexOf(".");
            if (lastSepPos != -1){
                ret = src.substring(lastSepPos+1, src.length() -1);
            }
        }
        return ret;
    }
}
